package com.wnhz.work.yz.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wnhz.work.yz.R;
import com.wnhz.work.yz.bean.YanShouDaiBean;
import com.wnhz.work.yz.listener.OnItemClickListener;
import com.wnhz.work.yz.utils.GlideImageLoader;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuAdapter;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2017/6/6.
 */
public class YanShouDaiAdapter extends SwipeMenuAdapter<YanShouDaiAdapter.DefaultViewHolder> {


    private OnItemClickListener mOnItemClickListener;
    private Context context;
    private List<YanShouDaiBean.InfoEntity> test = new ArrayList<>();
    private int type = 0;

    public YanShouDaiAdapter(List<YanShouDaiBean.InfoEntity> test, Context context, int type) {
        this.context = context;
        this.test = test;
        this.type = type;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }


    @Override
    public void onBindViewHolder(YanShouDaiAdapter.DefaultViewHolder holder, int position) {
        holder.setData(test.get(position));
        holder.setOnItemClickListener(mOnItemClickListener);
    }

    @Override
    public int getItemCount() {
        return test == null ? 0 : test.size();
    }

    @Override
    public View onCreateContentView(ViewGroup parent, int viewType) {
        return LayoutInflater.from(parent.getContext()).inflate(R.layout.item_yanshou_dai, parent, false);
    }

    @Override
    public YanShouDaiAdapter.DefaultViewHolder onCompatCreateViewHolder(View realContentView, int viewType) {
        return new DefaultViewHolder(realContentView);
    }


    class DefaultViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        Banner img;
        TextView hetonghao, name, time, address, anzhuang, or;
        ImageView select;
        LinearLayout ll_select;

        OnItemClickListener mOnItemClickListener;

        public DefaultViewHolder(View itemView) {
            super(itemView);
            itemView.setOnClickListener(this);
            img = (Banner) itemView.findViewById(R.id.img2);
            hetonghao = (TextView) itemView.findViewById(R.id.hetonghao);
            name = (TextView) itemView.findViewById(R.id.name);
            time = (TextView) itemView.findViewById(R.id.time);
            address = (TextView) itemView.findViewById(R.id.address);
            anzhuang = (TextView) itemView.findViewById(R.id.anzhuang);
            or = (TextView) itemView.findViewById(R.id.or);
            select = (ImageView) itemView.findViewById(R.id.select);
            ll_select = (LinearLayout) itemView.findViewById(R.id.ll_select);
        }

        public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
            this.mOnItemClickListener = onItemClickListener;
        }


        @Override
        public void onClick(View v) {
            if (mOnItemClickListener != null) {
                mOnItemClickListener.onItemClick(getAdapterPosition());
            }
        }


        public void setData(YanShouDaiBean.InfoEntity info) {
            if (info.getImg() != null && info.getImg().size() > 0) {
                //   x.image().bind(img, info.getImg().get(0));
                img.setImageLoader(new GlideImageLoader());
                //设置图片集合
                img.setImages(info.getImg());
                img.setBannerStyle(BannerConfig.NOT_INDICATOR);
                //banner设置方法全部调用完毕时最后调用
                img.start();
            }
            name.setText(info.getProject_name());
            hetonghao.setText("" + info.getBudget_no());
            time.setText("" + info.getCheck_time());
            address.setText("" + info.getAddress());
            anzhuang.setText("安装队：" + info.getInstall());
            if (type == 0) {
                or.setText("总套数：" + info.getAll_nums() + "套/未报检套数：" + info.getHas_nums() + "套");
            } else {
                or.setText("总套数：" + info.getAll_nums() + "套/已报检套数：" + info.getHas_nums() + "套");
            }


        }
    }


}

